// pages/collect/collect.js
const setting = require("../../http/env");
const httpApi = require("../../http/request"); //后续可以改为你自己的域名接口地址

Page({

  /**
   * 页面的初始数据
   */
  data: {
    //默认域名
    baseUrl: setting.baseUrl,
    region_area: ['山东省'],

    truename:'',
    age:'',
    phone:'',
    area_name:'山东省',
    onetime:true,
  },

  // 姓名
  get_truename: function(e) {
    var that = this;
    that.setData({
      truename: e.detail.value,
    })
  },
  // 年龄
  get_age: function(e) {
    var that = this;
    that.setData({
      age: e.detail.value,
    })
  },
  // 手机号
  get_phone: function(e) {
    var that = this;
    that.setData({
      phone: e.detail.value,
    })
  },
  // 修改地区
  change_address: function(e) {
    var that=this;
    var region_area=e.detail.value;
    console.log('picker发送选择改变，携带值为', e.detail.value)
    that.setData({
      region_area: region_area,
      area_name:region_area[0],
    })
  },

  //确认发布
  sub(e){
    var that=this;
   
    //列表
    var param={
      truename:that.data.truename,
      age:that.data.age,
      phone:that.data.phone,
      area_name:that.data.area_name,
    };

    if(that.data.onetime){
      that.setData({
        onetime:false,
      })
      if(param.truename==''){
        wx.showToast({
          title: '请输入姓名',
          icon: 'none',
          duration: 2000
        })
        that.setData({
          onetime:true,
        })
      }else if(param.age==''){
        wx.showToast({
          title: '请输入年龄',
          icon: 'none',
          duration: 2000
        })
        that.setData({
          onetime:true,
        })
      }else if(param.phone==''){
        wx.showToast({
          title: '请输入手机号',
          icon: 'none',
          duration: 2000
        })
        that.setData({
          onetime:true,
        })
      }else{
       
        httpApi.Post("/index/mesCollect", param).then((resInfo) => {
          console.log("resInfo", resInfo);
          wx.showToast({
            title: resInfo.msg,
            icon: 'none',
            duration: 2000
          })
          if(resInfo.status==-1){
            that.setData({
              onetime:true,
            })
          }
        });
      }
    }else{
      wx.showToast({
        title: '请不要重复提交',
        icon: 'none',
        duration: 2000
      })
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})